
package com.craterhill.java.ems.dao;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.BatchPreparedStatementSetter;

public interface EMSDao<T> {

	public final int ACTION_SAVE = 0;
	public final int ACTION_UPDATE = 1;

	public int save(final T t);

	public boolean update(final T t);

	public boolean remove(final Integer... ids);

	public T find(final int recordId);

	public List<T> findAll();

	public class DaoBatchPreparedStatementSetter implements BatchPreparedStatementSetter {

		private final Object[] parameters;

		public DaoBatchPreparedStatementSetter(final Object... parameters) {
			this.parameters = parameters;
		}

		@Override
		public int getBatchSize() {
			return parameters.length;
		}

		@Override
		public void setValues(PreparedStatement preparedStatement, int position) throws SQLException {
			Object userValueObject = parameters[position];
			if(userValueObject instanceof Integer){
				preparedStatement.setInt(position + 1, (Integer) userValueObject);
			}
		}
	}
}
